
package com.ibeeking.found.open.b.rest.controller.v1;

import com.ibeeking.found.common.annotation.IgnoreResult;
import com.ibeeking.found.open.api.common.query.FileNameQuery;
import com.ibeeking.found.open.api.feign.OpenFileFeignClient;
import com.ibeeking.found.open.b.rest.service.impl.MemberServiceImpl;
import feign.Response;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @ClassName WxOpenEventController
 * @Description 微信主动调用
 * @Author ibeeking
 * @Date 2021-06-10 16:23
 **/

@RestController
@RequestMapping("/v1/open/api/wxQrCode")
public class WxQrCodeController {

    @Resource
    private OpenFileFeignClient openFileFeignClient;

    @GetMapping(value = "/{fileName}")
    @IgnoreResult
    public void qrcodeCheck(@PathVariable("fileName") String fileName, HttpServletResponse response) {
        try {
            FileNameQuery query = new FileNameQuery();
            query.setPath("wxCheck/");
            query.setFileName(fileName);
            Response response1 = openFileFeignClient.queryFile(query);
            if (null != response1) {
                Response.Body body = response1.body();
                MemberServiceImpl.stream(body.asInputStream(), response.getOutputStream());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @GetMapping(value = "/{appId}/{fileName}")
    @IgnoreResult
    public void qrcodeAppIdCheck(@PathVariable("appId") String appId, @PathVariable("fileName") String fileName, HttpServletResponse response) {
        try {
            FileNameQuery query = new FileNameQuery();
            query.setPath("wxCheck/");
            query.setFileName(fileName);
            Response response1 = openFileFeignClient.queryFile(query);
            if (null != response1) {
                Response.Body body = response1.body();
                MemberServiceImpl.stream(body.asInputStream(), response.getOutputStream());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

